<html>
<head>
<title>管理系统</title>
<meta http-equiv=Content-Type content=text/html;charset=utf-8>
<#include "../inc/commonJs.html">
<script type="text/JavaScript">
	var grid, windowparam=0;
	$(function() {
		//分类管理表格  
		grid = $('#grid').datagrid({
	    url:'listClass.do',  
	    loadMsg:'数据加载中请稍后……',  
        striped: true,  
	    pagination: true,  
	    rownumbers: true, 
        singleSelect : true,  
        pageSize: [${syscfg.pageSize!10}],
        pageList: [${syscfg.pageList!10}],
        columns:[[  
             {field:'id',title: 'ID',align: 'center',width: '50'},  
             {field:'name',title: '名称',align: 'center',width: '230'},
             {field:'orders',title: '排序',align: 'center',width: '100'},
             {field:'zt',title: '状态',align: 'center',width: '100',
             	formatter: function(value,rowdata,index){
             		var str = '';
					if(value ==0){
						str += '<a id="btnadd" class="l-btn l-btn-plain" href="javascript:updateState('+rowdata.id+','+rowdata.zt+')"><span class="l-btn-left"><span class="l-btn-text icon-no l-btn-icon-left">启用</span></span></a>';
					}else{
						str += '<a id="btnadd" class="l-btn l-btn-plain" href="javascript:updateState('+rowdata.id+','+rowdata.zt+')"><span class="l-btn-left"><span class="l-btn-text icon-ok l-btn-icon-left">禁用</span></span></a>';
					}
					return str;
				}
             }]],
             toolbar : [btn_add, btn_edit, btn_del,"-"]
     });
	//
	$("#tree").tree({
	    method: "post",
	    lines: true,
	    url: "listClassForTree.do",
	    dataPlain: true,       //该属性用以启用当前 easyui-tree 控件对平滑数据格式的支持
	    toggleOnClick: false,
	    enableContextMenu: false,
	    onClick: function(node){
	        var params = {};
	        windowparam = node.id;
			params['fid'] = node.id;
			grid.datagrid('reload',params); 
		}
	});
	
  });
	function doAdd() {
		var url = '${request.contextPath}/xadmin/bbs/classWindow.do?windowparam='+windowparam;
		var mwin = top.modalwindow(url, grid,{ width:400,height:200,title:'新增论坛分类',
		    buttons:[{
				text:'保存',
				iconCls:"icon-save",
				handler:function(){
					mwin.find('iframe')[0].contentWindow.doSave($('#tree'));
				}
			}, top.btn_close]   
		});
	}	
	//工具栏修改用户
	function doEdit() {
		var selected =  grid.datagrid('getSelected');
		if(!selected){
			top.noselectedalert();
			return;
		}
		//
		var url = '${request.contextPath}/xadmin/bbs/classWindow.do?id='+selected.id+'&windowparam='+windowparam;
		var mwin = top.modalwindow(url, grid,{width:400, height:200,title:'修改论坛分类',
		    buttons:[{
				text:'保存',
				iconCls:"icon-save",
				handler:function(){
					mwin.find('iframe')[0].contentWindow.doSave($('#tree'));
				}
			}, top.btn_close]   
		});
	}
	//工具栏删除用户
	function doDel(){
		var selected =  grid.datagrid('getSelected');
		if(!selected){
			top.noselectedalert();
			return;
		}
		$.messager.confirm('系统提示', '<br>&nbsp;&nbsp;&nbsp;&nbsp;你确定要删除该信息?', function(r) {
			if (r) {
				$.post("delClass.do", { "id": selected.id},
				   function(data){
				   	grid.datagrid('reload');
				   	top.messagershow(data);
				});
			}
		});
	}
	//
	function updateState(id,result){
		if(result==0){
			result =1;
		}else{
			result = 0;
		}
		$.post("updateState.do", { "id": id,"result": result},
		   	function(data){
		   		grid.datagrid('reload'); 
		   		top.messagershow(data);
		});
	}
</script>

</head>
<body class="easyui-layout">
<div data-options="region:'west',iconCls:'icon-mini-add',title:'分类列表',split:true" style="width:180px;">
	<div class="easyui-panel" data-options='fit:true,border:false'> 
		<ul id="tree"></ul>
	</div>
</div>   
<div data-options="region:'center'">
<table id="grid" data-options="fit:true,border:false"></table>
</div>  
</body>
</html>